<template>
	<view>
		<view class="">
			<uni-nav-bar title="书架" :rightText="rightText" @clickRight="changeShelf"></uni-nav-bar>
		</view>
		<view class="">
			<bookCoolect ref="bookShelf" :dataList="dataList" :leftCheckBox="leftCheckBox"></bookCoolect>
		</view>
	</view>
</template>

<script>
	import * as DB from "../../compoment/DB.js"
	import {bookIsUpdateChapter,findDBShelfBook} from "@/compoment/index.js"
	export default {
		data() {
			return {
				dataList:[],
				leftCheckBox:false,
				rightText:"管理",
			}
		},
		onLoad() {
			this.all()
		},
		onShow() {
			this.all()
		},
		onPullDownRefresh() {
			this.all()
		},
		methods: {
			 all(){
				let open = DB.isOpen();
				if (open) {
					DB.selectBookAll("uu_bookShelf")
						.then(res => {
							this.dataList = res
							uni.stopPullDownRefresh()
						})
						.catch(error => {
							console.log(res.data,"查询异常")
						});
				}
			},
			changeShelf(){
				this.leftCheckBox=!this.leftCheckBox
				this.rightText=this.leftCheckBox?"删除":"管理"
				if(!this.leftCheckBox){
					let ids = this.$refs.bookShelf.ids
					let open = DB.isOpen();
					if (open) {
						DB.removeBookShelf(ids)
							.then(res => {
								this.all()
							})
							.catch(error => {
								console.log(res.data,"删除异常")
							});
					}
				}
			}
		}
	}
</script>

<style>

</style>
